package com.ruoyi.personnel.wechat.utils;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;

import java.util.HashMap;
import java.util.Map;

public class WechatUtil {

    public static JSONObject getSessionKeyOrOpenId(String code){
        String resquestUrl = WXContant.CODE_SESSION_URL;
        Map<String,String> requestUrlParam = new HashMap<>();

        //小程序appId
        requestUrlParam.put("appid",WXContant.APPID);
        //小程序secret
        requestUrlParam.put("secret",WXContant.SECRET);
        requestUrlParam.put("js_code",code);
        //默认参数
        requestUrlParam.put("grant_type","authorization_code");
        //发送Post请求 调用微信接口 获取openid 用户唯一标识
        JSONObject jsonObject = JSON.parseObject(HttpClientUtil.doPost(resquestUrl,requestUrlParam));
        return jsonObject;
    }

}